.\SetGlobalVariables.ps1

if ($Params.Debug -eq "true") {
	$DebugPreference = "Continue";
}

Write-Debug ("Generating working copy for: {0}" -f $Params.Source.SourceCodeDir)
.\GenerateBuild.ps1 $Params.Source.SourceCodeDir $Params.Source.ExcludePaths
Write-Debug "Generated working copy"

Write-Debug ("Generating zip '{0}'" -f $Params.Zip.ZipFileNameSource)
.\Tasks\zip.ps1 $Params.Zip.ZipFileNameSource $Params.TempBuildDir
Write-Debug "Generated zip"

Write-Debug ("Building source code '{0}'..." -f $Params.TempBuildDir)
.\Tasks\build.ps1 $Params.Source.MsBuildFile $Params.TempBuildDir
Write-Debug "Building source code done"

$binDir = [System.IO.Path]::Combine( $Params.TempBuildDir, "bin" )
New-Item $binDir -type directory
Write-Debug ("Grabbing binaries from '{0}' with expression '{1}' and copying them to '{2}'" -f $Params.TempBuildDir, $Params.Binaries.PathExpression, $binDir)
.\Tasks\getBinaries.ps1 $Params.TempBuildDir $Params.Binaries.PathExpression $binDir
Write-Debug "Binaries copied"

Write-Debug ("Generating zip '{0}'..." -f $Params.Zip.ZipFileNameBin)
.\Tasks\zip.ps1 $Params.Zip.ZipFileNameBin $binDir
Write-Debug "Generated zip"

if ($Params.Debug -eq "true") {
	$DebugPreference = "SilentlyContinue";
} 

if ($Params.RemoveTempDirOnFinish -eq "true") {
	Remove-Item $Params.TempDir -recurse
}

